home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE23 / SURVIVE / fmAllo.pas < prev    next >
Pascal/Delphi Source File  |  1997-05-19  |  4KB  |  145 lines

  1. unit fmAllo;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   Grids, StdCtrls, uBase, uAllo, dmData;
  8.  
  9. type
  10.   TfrmPaymentAllocation = class(TForm)
  11.     grpSummary: TGroupBox;
  12.     grpCredits: TGroupBox;
  13.     btnPost: TButton;
  14.     btnCancel: TButton;
  15.     btnDefault: TButton;
  16.     grdSummary: TStringGrid;
  17.     grdCredits: TStringGrid;
  18.     procedure grdSummaryTopLeftChanged(Sender: TObject);
  19.     procedure grdCreditsTopLeftChanged(Sender: TObject);
  20.     procedure grdCreditsSetEditText(Sender: TObject; ACol, ARow: Longint;
  21.       const Value: string);
  22.   private
  23.   public
  24.     AllocationInfo: TAllocationInfo;
  25.  
  26.     procedure PopulateForm;
  27.   end;
  28.  
  29. var
  30.   frmPaymentAllocation: TfrmPaymentAllocation;
  31.  
  32. function ShowPaymentAllocationDlg(aAllocInfo: TAllocationInfo): TModalResult;
  33.  
  34. implementation
  35.  
  36. {$R *.DFM}
  37.  
  38. { TfrmPaymentAllocation }
  39.  
  40. function ShowPaymentAllocationDlg(aAllocInfo: TAllocationInfo): TModalResult;
  41. begin
  42.   Application.CreateForm(TfrmPaymentAllocation, frmPaymentAllocation);
  43.   try
  44.     with frmPaymentAllocation do begin
  45.       AllocationInfo := aAllocInfo;
  46.       PopulateForm;
  47.       Result := ShowModal;
  48.     end;
  49.   finally
  50.     frmPaymentAllocation.Release;
  51.   end;
  52. end;
  53.  
  54. procedure TfrmPaymentAllocation.PopulateForm;
  55. var
  56.   I, J: Integer;
  57.   TotalPayment: LongInt;
  58. begin
  59.   with grdSummary do begin
  60.     Cells[0, 1] := 'Payment Amount';
  61.     Cells[0, 2] := 'Amount Remaining';
  62.     Cells[1, 0] := 'Total';
  63.  
  64.     with AllocationInfo do begin
  65.       ColCount := MethodCount + 2;
  66.       TotalPayment := 0;
  67.       for I := 0 to MethodCount - 1 do begin
  68.         Cells[I + 2, 0] := MethodName[I];
  69.         Cells[I + 2, 1] := Format(mskCurrency, [MethodAmounts[I] * 1.0]);
  70.  
  71.         ComputeTotalByMethod(I);
  72.         Cells[I + 2, 2] := Format(mskCurrency, [MethodAmountsRemaining[I] * 1.0]);
  73.         Inc(TotalPayment, MethodAmounts[I]);
  74.       end;
  75.       Cells[1, 1] := Format(mskCurrency, [TotalPayment * 1.0]);
  76.       Cells[1, 2] := Format(mskCurrency, [TotalPaymentRemaining * 1.0]);
  77.     end;
  78.   end;
  79.  
  80.   with grdCredits do begin
  81.     Cells[0, 0] := 'Amount';
  82.     Cells[1, 0] := 'Remaining';
  83.  
  84.     with AllocationInfo do begin
  85.       RowCount := Credits.Count + 1;
  86.       ColCount := MethodCount + 2;
  87.       for J := 0 to MethodCount - 1 do
  88.         Cells[J + FixedCols, 0] := MethodName[J];
  89.       for I := 0 to Credits.Count - 1 do begin
  90.         Cells[0, I + 1] := Format(mskCurrency, [Credits[I].Amount * 1.0]);
  91.         Cells[1, I + 1] := Format(mskCurrency, [Credits[I].AmountRemaining * 1.0]);
  92.         for J := 0 to MethodCount - 1 do
  93.           Cells[J + FixedCols, I + 1] := Format(mskCurrency, [Credits[I].PaymentByMethod[J] * 1.0]);
  94.       end;
  95.     end;
  96.   end;
  97. end;
  98.  
  99. procedure TfrmPaymentAllocation.grdSummaryTopLeftChanged(Sender: TObject);
  100. begin
  101.   grdCredits.LeftCol := grdSummary.LeftCol;
  102. end;
  103.  
  104. procedure TfrmPaymentAllocation.grdCreditsTopLeftChanged(Sender: TObject);
  105. begin
  106.   grdSummary.LeftCol := grdCredits.LeftCol;
  107. end;
  108.  
  109. procedure TfrmPaymentAllocation.grdCreditsSetEditText(Sender: TObject;
  110.   ACol, ARow: Longint; const Value: string);
  111. var
  112.   Total: LongInt;
  113.   I: Integer;
  114.   MethodNo: Integer;
  115.   CreditNo: Integer;
  116. begin
  117.   with grdCredits do
  118.   begin
  119.     MethodNo := ACol - FixedCols;
  120.     CreditNo := ARow - FixedRows;
  121.  
  122.     with AllocationInfo do begin
  123.       if Value = '' then
  124.         Credits[CreditNo].PaymentByMethod[MethodNo] := 0
  125.       else
  126.         Credits[CreditNo].PaymentByMethod[MethodNo] := StrToInt(Value);
  127.  
  128.       { Recompute the amount remaining for the payment method }
  129.       with grdSummary do begin
  130.         ComputeTotalByMethod(MethodNo);
  131.         Cells[FixedCols + MethodNo, 2] := Format(mskCurrency, [MethodAmountsRemaining[MethodNo] * 1.0]);
  132.         Cells[1, 2] := Format(mskCurrency, [TotalPaymentRemaining * 1.0]);
  133.       end;
  134.  
  135.       { Recompute the amount remaining for the marker }
  136.       Total := Credits[CreditNo].Amount;
  137.       for I := 0 to MethodCount - 1 do
  138.         Dec(Total, Credits[CreditNo].PaymentByMethod[I]);
  139.       grdCredits.Cells[1, FixedRows + CreditNo] := Format(mskCurrency, [Total * 1.0]);
  140.     end;
  141.   end;
  142. end;
  143.  
  144. end.
  145.